<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
</head>

<body>
  <div id="app">
    <h1>{{Counter}}</h1>
    <button-counter :num="Counter" @countevent="handleCount" ></button-counter>
    

  </div>


  <script>

    //全局组件
    Vue.component('ButtonCounter', {
      props:['num'],
      data() {
        return {
          count:0
        }
      },
      template: `
      <div>
      
      <button @click="increment">增加</button>
      <hr/>
    </div>
`,
      methods: {
        increment() {
          this.count = parseInt(this.count) + 1;
          this.$emit('countevent',this.count)
          //错误的写法，属性是单向数据流
          // this.num = 100;

        }
      }
    })

    var vm = new Vue({
      el: '#app',
     
      data: {
        Counter: 0
      },
      methods:{
        handleCount(num){
          console.log(num)
          this.Counter = num;
        }
      }
    })


  </script>


</body>

</html>